package com.example.three.Controller.RecommedConreoller;


import com.example.three.DO.RecommedGood;
import com.example.three.DO.TableData;
import com.example.three.Service.RecommedGoodService.RecommedService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller

@RequestMapping("")
public class RecommedController {
    @Resource
    private RecommedService recommedService;

    @RequestMapping("To-recommedlist")
    public String To_recommedlist(){

        return "/recommedlist";
    }

    @RequestMapping("/recommedlist")
    @ResponseBody
    public TableData recommedfindBy(HttpSession session, Model model,@RequestParam Map<String, Object> params){
        List<RecommedGood> recommedGoodList = recommedService.recommedfindBy();
        String prod_name=null;
        if(params.containsKey("keyWord")){
            prod_name=params.get("keyWord").toString();
        }


        if (prod_name == null || prod_name == "") {

        }
        else {
            recommedGoodList = (List<RecommedGood>)recommedService.recommedfindselect(prod_name);
        }
        TableData tableData = new TableData();
        tableData.setCode(0);
        tableData.setMsg("成功");
        tableData.setData(recommedGoodList);
        return tableData;

    }

    @RequestMapping("/recommeddelete")
    public void recommeddelete(String goodId){
        recommedService.recommeddelete(goodId);
    }

    @RequestMapping("/addrecommedgood")
    public String addshopgood(HttpSession session){

        return "addrecommedgood";
    }

    @RequestMapping("/addrecommedgood1")
    public String addshopgood1(String goodId,String goodName,String goodType,String recommed,double goodPrice,String goodLink){
        recommedService.addrecommed(goodId,goodName,goodType,recommed,goodPrice,goodLink);
        return "addrecommedgood";
    }
}
